package 扑克牌顺子;

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param numbers int整型一维数组
     * @return bool布尔型
     */
    public boolean IsContinuous(int[] numbers) {
        Arrays.sort(numbers);
        int cnt = 0, n = numbers.length, i = 0;
        while (i < n && numbers[i] == 0) {
            i++;
            cnt++;
        }
        if (cnt == 4) {
            return true;
        }
        for (; i < n - 1; i++) {
            if (numbers[i + 1] - numbers[i] != 1) {
                if (numbers[i] == numbers[i + 1]) {
                    return false;
                }
                cnt -= (numbers[i + 1] - numbers[i] - 1);
                if (cnt < 0) {
                    return false;
                }
            }
        }
        return true;
    }
}